package com.durian.finance.controller;

import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.web.page.TableDataInfo;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.finance.service.IJrRentInstallmentDetailService;
import com.durian.financial.api.domain.JrRentInstallmentDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房租分期申请详情Controller
 * 
 * @author durian
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/detail")
public class JrRentInstallmentDetailController extends BaseController
{
    @Autowired
    private IJrRentInstallmentDetailService jrRentInstallmentDetailService;

    /**
     * 查询房租分期申请详情列表
     */
    @RequiresPermissions("finance:detail:list")
    @GetMapping("/list")
    public TableDataInfo list(JrRentInstallmentDetail jrRentInstallmentDetail)
    {
        startPage();
        List<JrRentInstallmentDetail> list = jrRentInstallmentDetailService.selectJrRentInstallmentDetailList(jrRentInstallmentDetail);
        return getDataTable(list);
    }

    /**
     * 导出房租分期申请详情列表
     */
    @RequiresPermissions("finance:detail:export")
    @Log(title = "房租分期申请详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JrRentInstallmentDetail jrRentInstallmentDetail)
    {
        List<JrRentInstallmentDetail> list = jrRentInstallmentDetailService.selectJrRentInstallmentDetailList(jrRentInstallmentDetail);
        ExcelUtil<JrRentInstallmentDetail> util = new ExcelUtil<JrRentInstallmentDetail>(JrRentInstallmentDetail.class);
        util.exportExcel(response, list, "房租分期申请详情数据");
    }

    /**
     * 获取房租分期申请详情详细信息
     */
    @RequiresPermissions("finance:detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jrRentInstallmentDetailService.selectJrRentInstallmentDetailById(id));
    }

    /**
     * 新增房租分期申请详情
     */
    @RequiresPermissions("finance:detail:add")
    @Log(title = "房租分期申请详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JrRentInstallmentDetail jrRentInstallmentDetail)
    {
        return toAjax(jrRentInstallmentDetailService.insertJrRentInstallmentDetail(jrRentInstallmentDetail));
    }

    /**
     * 修改房租分期申请详情
     */
    @RequiresPermissions("finance:detail:edit")
    @Log(title = "房租分期申请详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JrRentInstallmentDetail jrRentInstallmentDetail)
    {
        return toAjax(jrRentInstallmentDetailService.updateJrRentInstallmentDetail(jrRentInstallmentDetail));
    }

    /**
     * 删除房租分期申请详情
     */
    @RequiresPermissions("finance:detail:remove")
    @Log(title = "房租分期申请详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jrRentInstallmentDetailService.deleteJrRentInstallmentDetailByIds(ids));
    }
}
